package com.wwwarehouse.contract.orders.import_order;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.wwwarehouse.common.activity.BaseCardDeskActivity;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.eventbus_event.CardDeskEvent;
import com.wwwarehouse.common.tools.rsa.StringUtils;

import contract.wwwarehouse.com.contract.R;
import de.greenrobot.event.EventBus;

/**
 * 订单导入设置-->提交页面
 * Created by ShineF on 2017/8/17 0017.
 */

public class ImportOrdersDetailsSubmitFragment extends BaseFragment implements View.OnClickListener {

    private View mRootView;
    private TextView mTvSubmitContent;
    private TextView mTvSubmitInfo;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mRootView = inflater.inflate(R.layout.fragment_import_orders_details_submit, container, false);
        return mRootView;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ((BaseCardDeskActivity) mActivity).hideBackBt();
        mTvSubmitContent = findView(mRootView, R.id.tv_submit_content);
        mTvSubmitInfo = $(R.id.tv_submit_info);
        Button mBtnComplete = findView(mRootView, R.id.btn_complete);
        mBtnComplete.setOnClickListener(this);

    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof ImportOrdersDetailsSubmitFragment) {
            mActivity.setTitle(R.string.edit_success_submit);
        }
    }

    @Override
    public void requestDatas() {
        Bundle bundle = getArguments();
        if (bundle != null) {
            String startTime = bundle.getString("startTime");
            String endTime = bundle.getString("endTime");
            int status = bundle.getInt("status");
            if (status == 0) {
                mTvSubmitInfo.setText(getString(R.string.submit_success_info));
            } else if (status == 1) {
                mTvSubmitInfo.setText(getString(R.string.edit_success_info));
            }
            int submitType = bundle.getInt("submitType");
            if (submitType == 1) {
                mTvSubmitContent.setText(getString(R.string.import_submit_content_type_1));
            } else if (submitType == 2) {
                mTvSubmitContent.setText(getString(R.string.import_submit_content_type_2));
            } else if (submitType == 3) {
                mTvSubmitContent.setText(StringUtils.getSpannedHtml(mActivity, R.string.import_submit_content_type_3, startTime, endTime));
            } else if (submitType == 4) {
                mTvSubmitContent.setText(StringUtils.getSpannedHtml(mActivity, R.string.import_submit_content_type_4, startTime));
            } else if (submitType == 5) {
                mTvSubmitContent.setText(StringUtils.getSpannedHtml(mActivity, R.string.import_submit_content_type_5, endTime));
            }
        }
        // TODO: 2017/9/27 0027 禁止返回键
    }

    @Override
    public void onClick(View v) {
        if (R.id.btn_complete == v.getId()) {
            EventBus.getDefault().post(new CardDeskEvent("clear_back_stack"));
            pushFragment(new ImportOrdersPagersPagerFragment());
        }
    }



}
